/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

/**
 *
 * @author Mauricio
 */
public class JPopupMenuJPanelDibujo extends JPopupMenu implements ActionListener {
    
    //JPanelDibujo panelDibujo;
    private JVentana ventana;
    ArrayList<JMenuItem> itemsJFIgura;
    ArrayList<JMenuItem> itemsAreaVacia;
    ArrayList<JMenuItem> itemsFlecha;
    
    
    public JPopupMenuJPanelDibujo(){
        //this.panelDibujo = panel;
        this.itemsJFIgura = new ArrayList<>();
        this.itemsAreaVacia = new ArrayList<>();
        this.itemsFlecha = new ArrayList<>();
        this.ventana = null;
        
        // click en figura
        JMenuItem popEliminar = new JMenuItem (CommandNames.COMMAND_ELIMINAR_RAMO); 
        popEliminar.setActionCommand(CommandNames.COMMAND_ELIMINAR_RAMO);
        JMenuItem popEditar = new JMenuItem (CommandNames.COMMAND_EDITAR_RAMO); 
        popEditar.setActionCommand(CommandNames.COMMAND_EDITAR_RAMO);
        this.itemsJFIgura.add(popEliminar);
        this.itemsJFIgura.add(popEditar);
        
        // click en area vacia
        JMenuItem popNuevo = new JMenuItem(CommandNames.COMMAND_NUEVO_RAMO);
        this.itemsAreaVacia.add(popNuevo);

        // click en flecha
        JMenuItem popAgregarSegmento = new JMenuItem ("Agregar segmento");
        this.itemsFlecha.add(popAgregarSegmento);
        
        popEliminar.addActionListener(this);
        popEditar.addActionListener(this);
        popNuevo.addActionListener(this);
        popAgregarSegmento.addActionListener(this);
    }
    
    public void show(Component c, int x, int y, String id){
        super.removeAll();
        switch (id) {
            case "figura":
                for (JMenuItem item : this.itemsJFIgura){
                    super.add(item);
                }
                break;
            case "espacio vacio":
                for (JMenuItem item : this.itemsAreaVacia){
                    super.add(item);
                }
                break;
            case "flecha":
                for (JMenuItem item : this.itemsFlecha){
                    super.add(item);
                }
                break;
        }
        super.show(c, x, y);
    }


    @Override
    public void actionPerformed(ActionEvent e) {
//        String accion = e.getActionCommand();
//        if (accion.equals(CommandNames.COMMAND_ELIMINAR_RAMO)){
//            this.ventana.actionPerformed(e);
//        }
//        else if (accion.equals(CommandNames.COMMAND_NUEVO_RAMO)){
//            this.ventana.actionPerformed(e);
//        }
        this.ventana.actionPerformed(e);
    }
    
    public void setVentana(JVentana v){
        this.ventana = v;
    }
    

}
